/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Andrés Felipe
 */
@Entity
@Table(name = "\"javeriana.sc.cc\".\"t_productXsales\"")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ProductXsales.findAll", query = "SELECT p FROM ProductXsales p"),
    @NamedQuery(name = "ProductXsales.findByProductid", query = "SELECT p FROM ProductXsales p WHERE p.productXsalesPK.productid = :productid"),
    @NamedQuery(name = "ProductXsales.findBySaleid", query = "SELECT p FROM ProductXsales p WHERE p.productXsalesPK.saleid = :saleid"),
    @NamedQuery(name = "ProductXsales.findByQuantity", query = "SELECT p FROM ProductXsales p WHERE p.quantity = :quantity")})
public class ProductXsales implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ProductXsalesPK productXsalesPK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "quantity")
    private int quantity;
    @JoinColumn(name = "saleid", referencedColumnName = "saleid", insertable = false, updatable = false)
    @ManyToOne(optional = false,cascade = CascadeType.REMOVE)
    private Sales sales;
    @JoinColumn(name = "productid", referencedColumnName = "idproduct", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Product product;

    public ProductXsales() {
    }

    public ProductXsales(ProductXsalesPK productXsalesPK) {
        this.productXsalesPK = productXsalesPK;
    }

    public ProductXsales(ProductXsalesPK productXsalesPK, int quantity) {
        this.productXsalesPK = productXsalesPK;
        this.quantity = quantity;
    }

    public ProductXsales(int productid, int saleid) {
        this.productXsalesPK = new ProductXsalesPK(productid, saleid);
    }

    public ProductXsalesPK getProductXsalesPK() {
        return productXsalesPK;
    }

    public void setProductXsalesPK(ProductXsalesPK productXsalesPK) {
        this.productXsalesPK = productXsalesPK;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public Sales getSales() {
        return sales;
    }

    public void setSales(Sales sales) {
        this.sales = sales;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (productXsalesPK != null ? productXsalesPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ProductXsales)) {
            return false;
        }
        ProductXsales other = (ProductXsales) object;
        if ((this.productXsalesPK == null && other.productXsalesPK != null) || (this.productXsalesPK != null && !this.productXsalesPK.equals(other.productXsalesPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.ProductXsales[ productXsalesPK=" + productXsalesPK + " ]";
    }
    
}
